package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp login(String username,String password) {
        Emp loginEmp = empMapper.login(username,password);
        return loginEmp;
    }

    @Override
    public PageBean page(Integer page, Integer pageSize) {
        //获取总数
        Long total = empMapper.count();
        Integer start = (page - 1) * pageSize;
        List<Emp> empList = empMapper.page(start,pageSize);
        PageBean pageBean = new PageBean(total,empList);
        return pageBean;
    }

    @Override
    public void add(Emp emp) {
        empMapper.insert(emp);
    }

    @Override
    public boolean findByPhone(String phone) {
        Emp emp = empMapper.findByPhone(phone);
        if(emp != null) {
            return true;
        }
        return false;
    }

    @Override
    public boolean findById(Integer id) {
        Emp emp = empMapper.findById(id);
        if(emp == null) {
            return false;
        }
        return true;
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }

    @Override
    public void delete(Integer id) {
        empMapper.delete(id);
    }

    @Override
    public void deletes(List<Integer> ids) {
        empMapper.deletes(ids);
    }
}
